package com.healthy.support.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.support.domain.Agents;
import com.healthy.support.service.IAgentsService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 客服人员Controller
 * 
 * @author 束伟
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/Agents")
public class AgentsController extends BaseController
{
    @Autowired
    private IAgentsService agentsService;

    /**
     * 查询客服人员列表
     */
    @RequiresPermissions("support:Agents:list")
    @GetMapping("/list")
    public TableDataInfo list(Agents agents)
    {
        startPage();
        List<Agents> list = agentsService.selectAgentsList(agents);
        return getDataTable(list);
    }

    /**
     * 导出客服人员列表
     */
    @RequiresPermissions("support:Agents:export")
    @Log(title = "客服人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Agents agents)
    {
        List<Agents> list = agentsService.selectAgentsList(agents);
        ExcelUtil<Agents> util = new ExcelUtil<Agents>(Agents.class);
        util.exportExcel(response, list, "客服人员数据");
    }

    /**
     * 获取客服人员详细信息
     */
    @RequiresPermissions("support:Agents:query")
    @GetMapping(value = "/{agentId}")
    public AjaxResult getInfo(@PathVariable("agentId") Long agentId)
    {
        return success(agentsService.selectAgentsByAgentId(agentId));
    }

    /**
     * 新增客服人员
     */
    @RequiresPermissions("support:Agents:add")
    @Log(title = "客服人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Agents agents)
    {
        return toAjax(agentsService.insertAgents(agents));
    }

    /**
     * 修改客服人员
     */
    @RequiresPermissions("support:Agents:edit")
    @Log(title = "客服人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Agents agents)
    {
        return toAjax(agentsService.updateAgents(agents));
    }

    /**
     * 删除客服人员
     */
    @RequiresPermissions("support:Agents:remove")
    @Log(title = "客服人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agentIds}")
    public AjaxResult remove(@PathVariable Long[] agentIds)
    {
        return toAjax(agentsService.deleteAgentsByAgentIds(agentIds));
    }
}
